package com.example.qxfw.dlqx.service.impl;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.example.qxfw.common.entity.zy.PowerLoadHourFcst;
import com.example.qxfw.dlqx.mapper.PowerLoadHourFcstMapper;
import com.example.qxfw.dlqx.service.PowerLoadHourFcstService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.sql.Timestamp;
import java.util.List;

@Service
public class PowerLoadHourFcstServiceImpl implements PowerLoadHourFcstService {

    @Autowired
    private PowerLoadHourFcstMapper powerLoadHourFcstMapper;

    @Override
    public List<PowerLoadHourFcst> listByDateChar(String dateChar) {
        return powerLoadHourFcstMapper.selectList(Wrappers.<PowerLoadHourFcst>lambdaQuery()
                .eq(PowerLoadHourFcst::getDatechar, Timestamp.valueOf(dateChar)));
    }

    @Override
    public List<PowerLoadHourFcst> listByParams(String dateChar1, String dateChar2) {
        return powerLoadHourFcstMapper.selectList(Wrappers.<PowerLoadHourFcst>lambdaQuery()
                .between(PowerLoadHourFcst::getDatechar, Timestamp.valueOf(dateChar1),Timestamp.valueOf(dateChar2))
                .orderByAsc(PowerLoadHourFcst::getDatechar));
    }

    @Override
    public Integer update(PowerLoadHourFcst powerLoadHourFcst) {
        return powerLoadHourFcstMapper.update(powerLoadHourFcst,Wrappers.<PowerLoadHourFcst>lambdaUpdate()
                .eq(PowerLoadHourFcst::getDatechar, new Timestamp(powerLoadHourFcst.getDatechar().getTime())));
    }

    @Override
    public Integer save(PowerLoadHourFcst powerLoadHourFcst) {
        return powerLoadHourFcstMapper.insert(powerLoadHourFcst);
    }
}
